home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / piclens-1.7.0.3459-fx-win.xpi / components / piclensjshelper.js < prev    next >
Text File  |  2008-06-16  |  3KB  |  86 lines

  1. // Copyright 2008, Cooliris Inc.
  2.  
  3. function PicLensJSHelper() {}
  4.  
  5. PicLensJSHelper.prototype = {
  6.     xpiPath getter: function() {
  7.         return __LOCATION__.parent.parent.path;
  8.     },
  9.     frontDocument getter: function() {
  10.         var tabBrowser = this._frontTabBrowser();
  11.         if (tabBrowser) {
  12.             var tab = tabBrowser.selectedBrowser;
  13.             return tab.contentDocument;
  14.         } else {
  15.             return null;
  16.         }
  17.     },
  18.     openUrl: function(url, newTab, selectTab) {
  19.         var tabBrowser = this._frontTabBrowser();
  20.         if (!tabBrowser) {
  21.             return;
  22.         }
  23.         if (newTab) {
  24.             var tab = tabBrowser.addTab(url);
  25.             if (selectTab) tabBrowser.selectedTab = tab;
  26.         } else {
  27.             tabBrowser.selectedBrowser.contentDocument.location = url;
  28.         }
  29.     },
  30.  
  31.     setToolbarLaunchIcon: function(win, doc, name) {
  32.         var button = win.document.getElementById('piclens-toolbarbutton2');
  33.         var selectedDoc = win.getBrowser().selectedBrowser.contentDocument;
  34.         if (button && doc === selectedDoc) {
  35.             button.className = "piclens-toolbarbutton-" + name;
  36.         }
  37.     },
  38.  
  39.     _frontTabBrowser: function() {
  40.         var mediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  41.             .getService(Components.interfaces.nsIWindowMediator);
  42.         var win = mediator.getMostRecentWindow("navigator:browser");
  43.         return win ? win.getBrowser() : null;
  44.     },
  45.  
  46.     QueryInterface: function(iid) {
  47.         if (!iid.equals(Components.interfaces.IPicLensJSHelper) &&
  48.             !iid.equals(Components.interfaces.nsISupports))
  49.             throw Components.results.NS_ERROR_NO_INTERFACE;
  50.         return this;
  51.     }
  52. };
  53.  
  54. var PicLensJSHelperModule = {
  55.     registerSelf: function(compMgr, fileSpec, location, type) {
  56.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  57.         compMgr.registerFactoryLocation(this.classId, this.className, this.contractId,
  58.             fileSpec, location, type);
  59.     },
  60.     getClassObject: function(compMgr, cid, iid) {
  61.         if (!cid.equals(this.classId))
  62.             throw Components.results.NS_ERROR_NO_INTERFACE;
  63.         if (!iid.equals(Components.interfaces.nsIFactory))
  64.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  65.         return this.factory;
  66.     },
  67.     canUnload: function(compMgr) {
  68.         return true;
  69.     },
  70.     
  71.     classId: Components.ID("a0ff7c31-77e1-4d6a-a6c6-c312ec2fbed4"),
  72.     className: "PicLensJSHelper",
  73.     contractId: "@cooliris.com/piclens/jshelper;1",
  74.     factory: {
  75.         createInstance: function(outer, iid) {
  76.             if (outer != null)
  77.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  78.             return (new PicLensJSHelper()).QueryInterface(iid);
  79.         }
  80.     }
  81. };
  82.  
  83. function NSGetModule(compMgr, fileSpec) {
  84.     return PicLensJSHelperModule;
  85. }
  86.